package ufpr.ees.suhck.dao.usuario;

import java.util.List;
import org.hibernate.Query;
import ufpr.ees.suhck.dao.GenericDaoImpl;
import ufpr.ees.suhck.db.HibernateUtil;
import ufpr.ees.suhck.model.Medico;

public class MedicoDaoImpl extends GenericDaoImpl<Medico, Long> implements MedicoDao {

    public Medico findPorEmail(String email) {
        sf = HibernateUtil.getSessionFactory().openSession();
        Query query = sf.getNamedQuery(Medico.FIND_POR_EMAIL);
        query.setParameter("email", email);
        List<Medico> medicos = query.list();
        sf.close();
        if (medicos.size() > 0) {
            return medicos.get(0);
        }
        return null;
    }

    public List<Medico> findPorCrm(String crm) {
        sf = HibernateUtil.getSessionFactory().openSession();
        Query query = sf.getNamedQuery(Medico.FIND_POR_CRM);
        query.setParameter("crm", "%" + crm + "%");
        List<Medico> medicos = query.list();
        sf.close();
        return medicos;
    }

    public List<Medico> findPorEsp(String especialidade) {
        sf = HibernateUtil.getSessionFactory().openSession();
        Query query = sf.getNamedQuery(Medico.FIND_POR_ESP);
        query.setParameter("especialidade", "%" + especialidade + "%");
        List<Medico> medicos = query.list();
        sf.close();
        return medicos;
    }
}
